home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_5 / issue_06 / benchmarks / c_source / dry < prev    next >
Encoding:
Text File  |  1991-06-04  |  13.0 KB  |  445 lines

  1. /*
  2.  *      "DHRYSTONE" Benchmark Program
  3.  *
  4.  *      Version:        C/1
  5.  *      Date:           12/01/84, RESULTS updated 10/15/85
  6.  *      Author:         Reinhold P. Weicker,  CACM Vol 27, No 10, 10/84 pg. 1013
  7.  *                      Translated from ADA by Rick Richardson
  8.  *                      Every method to preserve ADA-likeness has been used,
  9.  *                      at the expense of C-ness.
  10.  *      Compile:        cc -O dry.c -o drynr                    : No registers
  11.  *                      cc -O -DREG=register dry.c -o dryr      : Registers
  12.  *      Defines:        Defines are provided for old C compiler's
  13.  *                      which don't have enums, and can't assign structures.
  14.  *                      The time(2) function is library dependant; One is
  15.  *                      provided for CI-C86.  Your compiler may be different.
  16.  *      Run:            drynr; dryr
  17.  *                      50000 Runs are made and the time is printed
  18.  *      Results:        If you get any new machine/OS results, please send to:
  19.  *                              ..!houxm!vaximile!rer
  20.  *                      and thanks to all that do.  Space prevents listing
  21.  *                      the names of those who have provided some of these
  22.  *                      results.
  23.  *
  24.  * MACHINE      MICROPROCESSOR  OPERATING       COMPILER        DHRYSTONES/SEC.
  25.  * TYPE                         SYSTEM                          NO REG  REGS
  26.  * --------------------------   ------------    -----------     ---------------
  27.  * IBM PC/XT    8088-4.77Mhz    PCDOS 2.1       CI-C86 2.1      ????    ????
  28.  * IBM PC/XT    8088-4.77Mhz    PC/IX           cc              ????    ????
  29.  * XT Clone     v20-8.Mhz       PCDOS 3.3       MSC 4.0         0630    0684
  30.  * Lisa         68000-7.7Mhz    ????            ??              ????    ????
  31.  * IBM PC/XT    8088-4.77Mhz    VENIX/86 2.0    cc               297     324
  32.  * ATT PC6300   8086-8Mhz       MSDOS 2.11      b16cc 2.0        632     684
  33.  * IBM PC/AT    80286-6Mhz      PCDOS 3.0       CI-C86 2.1       666     684
  34.  * Macintosh    68000-7.7Mhz    -               MegaMax C 2.0    661     709
  35.  * ATT PC6300   8086-8Mhz       MSDOS 2.11      CI-C86 2.20M     769     769
  36.  * ATT 3B2/300  MAC32-?Mhz      UNIX 5.0.2      cc               735     806
  37.  * Fast Mac     68000-7.7Mhz    -               MegaMax C 2.0    839     904 +
  38.  * IBM PC/AT    80286-6Mhz      VENIX/86 2.1    cc               961    1000
  39.  * VAX 11/750   -               VMS             VAX-11 C 2.0     958    1091
  40.  * ATT PC7300   68010-10Mhz     UNIX 5.2        cc              1041    1111
  41.  * Sun2/120     68010-10Mhz     Sun 4.2BSD      cc              1136    1219
  42.  * PDP 11/70    -               UNIX 5.2        cc              1162    1250
  43.  * IBM PC/AT    80286-7.5Mhz    VENIX/86 2.1    cc              1190    1315 *
  44.  * VAX 11/780   -               UNIX 5.2        cc              1515    1562
  45.  * ATT 3B20     -               UNIX 5.2        cc              1515    1724
  46.  * Gould PN6005 -               UTX 1.1(4.2BSD) cc              1675    1964
  47.  * Amdahl 580   -               UTS 5.0 Rel 1.2 cc Ver. 1.5    23076   23076
  48.  *
  49.  *   * 15Mhz crystal substituted for original 12Mhz;
  50.  *   + This Macintosh was upgraded from 128K to 512K in such a way that
  51.  *     the new 384K of memory is not slowed down by video generator accesses.
  52.  *
  53.  **************************************************************************
  54.  *
  55.  *      The following program contains statements of a high-level programming
  56.  *      language (C) in a distribution considered representative:
  57.  *
  58.  *      assignments                     53%
  59.  *      control statements              32%
  60.  *      procedure, function calls       15%
  61.  *
  62.  *      100 statements are dynamically executed.  The program is balanced with
  63.  *      respect to the three aspects:
  64.  *              - statement type
  65.  *              - operand type (for simple data types)
  66.  *              - operand access
  67.  *                      operand global, local, parameter, or constant.
  68.  *
  69.  *      The combination of these three aspects is balanced only approximately.
  70.  *
  71.  *      The program does not compute anything meaningfull, but it is
  72.  *      syntactically and semantically correct.
  73.  *
  74.  */
  75.  
  76. #include <stdio.h>
  77.  
  78. /* Compiler dependent options */
  79.  
  80. /*  NOENUM          Define if compiler has no enum's        */
  81. /*  NOSTRUCTASSIGN  Define if no structure assignment       */
  82. /*  NOTIME          Define if no time() function in library */
  83.  
  84. #ifdef  NOSTRUCTASSIGN
  85. #define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
  86. #else
  87. #define structassign(d, s)      d = s
  88. #endif
  89.  
  90. #ifdef  NOENUM
  91. #define Ident1  1
  92. #define Ident2  2
  93. #define Ident3  3
  94. #define Ident4  4
  95. #define Ident5  5
  96. typedef int     Enumeration;
  97. #else
  98. typedef enum    {Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
  99. #endif
  100.  
  101. typedef int     OneToThirty;
  102. typedef int     OneToFifty;
  103. typedef char    CapitalLetter;
  104. typedef char    String30[31];
  105. typedef int     Array1Dim[51];
  106. typedef int     Array2Dim[51][51];
  107.  
  108. struct  Record
  109. {
  110.         struct Record           *PtrComp;
  111.         Enumeration             Discr;
  112.         Enumeration             EnumComp;
  113.         OneToFifty              IntComp;
  114.         String30                StringComp;
  115. } R1,R2;
  116.  
  117. typedef struct Record   RecordType;
  118. typedef RecordType *    RecordPtr;
  119. typedef int             boolean;
  120. #undef NULL
  121. #define NULL            0
  122. #define TRUE            1
  123. #define FALSE           0
  124.  
  125. #define TIME
  126. #ifndef REG
  127. #define REG
  128. #endif
  129.  
  130. /* extern scounter(),rcounter();           ?? timer routines for 386/20 */
  131. extern Enumeration      Func1();
  132. extern boolean          Func2();
  133.  
  134. main()
  135. {
  136.         Proc0();
  137.     exit(0);
  138. }
  139.  
  140. /*
  141.  * Package 1
  142.  */
  143. int             IntGlob;
  144. boolean         BoolGlob;
  145. char            Char1Glob;
  146. char            Char2Glob;
  147. Array1Dim       Array1Glob;
  148. Array2Dim       Array2Glob;
  149. RecordPtr       PtrGlb;
  150. RecordPtr       PtrGlbNext;
  151.  
  152. Proc0()
  153. {
  154.         OneToFifty              IntLoc1;
  155.         REG OneToFifty          IntLoc2;
  156.         OneToFifty              IntLoc3;
  157.         REG char                CharLoc;
  158.         REG char                CharIndex;
  159.         Enumeration             EnumLoc;
  160.         String30                String1Loc;
  161.         String30                String2Loc;
  162.  
  163. #define LOOPS           500000
  164. #ifdef TIME
  165. long                    time();
  166. long                    starttime;
  167. long                    benchtime;
  168. long                    nulltime;
  169. #endif
  170. register /* unsigned */ long   i;
  171. #ifdef TIME
  172. starttime = time(0);
  173. for (i = 0; i < LOOPS; ++i);
  174. nulltime = time(0) - starttime;
  175. #endif
  176.  
  177.         PtrGlbNext = (RecordPtr) &R1; /*malloc(sizeof(RecordType));*/
  178.         PtrGlb = (RecordPtr) &R2; /*malloc(sizeof(RecordType));*/
  179.         PtrGlb->PtrComp = PtrGlbNext;
  180.         PtrGlb->Discr = Ident1;
  181.         PtrGlb->EnumComp = Ident3;
  182.         PtrGlb->IntComp = 40;
  183.         strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  184.  
  185. /*      These missing in Version 1.0
  186.         strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  187.         Array2Glob[8][7] = 10;
  188. */
  189.  
  190. /*****************
  191. -- Start Timer --
  192. *****************/
  193. #ifdef TIME
  194. starttime = time(0);
  195. #endif
  196. /* scounter(); */
  197. printf("Start Timing....\n\n");
  198.  
  199. for (i = 0; i < LOOPS; ++i)
  200. {
  201.  
  202.         Proc5();
  203.         Proc4();
  204.         IntLoc1 = 2;
  205.         IntLoc2 = 3;
  206.         strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  207.         EnumLoc = Ident2;
  208.         BoolGlob = ! Func2(String1Loc, String2Loc);
  209.         while (IntLoc1 < IntLoc2)
  210.         {
  211.                 IntLoc3 = 5 * IntLoc1 - IntLoc2;
  212.                 Proc7(IntLoc1, IntLoc2, &IntLoc3);
  213.                 ++IntLoc1;
  214.         }
  215.         Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  216.         Proc1(PtrGlb);
  217.         for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  218.                 if (EnumLoc == Func1(CharIndex, 'C'))
  219.                         Proc6(Ident1, &EnumLoc);
  220.         IntLoc3 = IntLoc2 * IntLoc1;
  221.         IntLoc2 = IntLoc3 / IntLoc1;
  222.         IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  223.         Proc2(&IntLoc1);
  224.  
  225. /*****************
  226. -- Stop Timer --
  227. *****************/
  228. }
  229. #ifdef TIME
  230. benchtime = time(0) - starttime - nulltime;
  231. #endif
  232. /* rcounter(); */
  233. printf("Stop Timing...\n\n");
  234. printf("Dhrystone time for %ld passes = %ld\n", (long) LOOPS, benchtime);
  235. printf("This machine benchmarks at %ld dhrystones/second\n",
  236.         ((long) LOOPS) / benchtime);
  237.  
  238. }
  239.  
  240. Proc1(PtrParIn)
  241. REG RecordPtr   PtrParIn;
  242. {
  243. #define NextRecord      (*(PtrParIn->PtrComp))
  244.  
  245.         structassign(NextRecord, *PtrGlb);
  246.         PtrParIn->IntComp = 5;
  247.         NextRecord.IntComp = PtrParIn->IntComp;
  248.         NextRecord.PtrComp = PtrParIn->PtrComp;
  249.         Proc3(NextRecord.PtrComp);
  250.         if (NextRecord.Discr == Ident1)
  251.         {
  252.                 NextRecord.IntComp = 6;
  253.                 Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
  254.                 NextRecord.PtrComp = PtrGlb->PtrComp;
  255.                 Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
  256.         }
  257.         else
  258.                 structassign(*PtrParIn, NextRecord);
  259.  
  260. #undef  NextRecord
  261. }
  262.  
  263. Proc2(IntParIO)
  264. OneToFifty      *IntParIO;
  265. {
  266.         REG OneToFifty          IntLoc;
  267.         REG Enumeration         EnumLoc;
  268.  
  269.         IntLoc = *IntParIO + 10;
  270.         for(;;)
  271.         {
  272.                 if (Char1Glob == 'A')
  273.                 {
  274.                         --IntLoc;
  275.                         *IntParIO = IntLoc - IntGlob;
  276.                         EnumLoc = Ident1;
  277.                 }
  278.                 if (EnumLoc == Ident1)
  279.                         break;
  280.         }
  281. }
  282.  
  283. Proc3(PtrParOut)
  284. RecordPtr       *PtrParOut;
  285. {
  286.         if (PtrGlb != NULL)
  287.                 *PtrParOut = PtrGlb->PtrComp;
  288.         else
  289.                 IntGlob = 100;
  290.         Proc7(10, IntGlob, &PtrGlb->IntComp);
  291. }
  292.  
  293. Proc4()
  294. {
  295.         REG boolean     BoolLoc;
  296.  
  297.         BoolLoc = Char1Glob == 'A';
  298.         BoolLoc |= BoolGlob;
  299.         Char2Glob = 'B';
  300. }
  301.  
  302. Proc5()
  303. {
  304.         Char1Glob = 'A';
  305.         BoolGlob = FALSE;
  306. }
  307.  
  308. extern boolean Func3();
  309.  
  310. Proc6(EnumParIn, EnumParOut)
  311. REG Enumeration EnumParIn;
  312. REG Enumeration *EnumParOut;
  313. {
  314.         *EnumParOut = EnumParIn;
  315.         if (! Func3(EnumParIn) )
  316.                 *EnumParOut = Ident4;
  317.         switch (EnumParIn)
  318.         {
  319.         case Ident1:    *EnumParOut = Ident1; break;
  320.         case Ident2:    if (IntGlob > 100) *EnumParOut = Ident1;
  321.                         else *EnumParOut = Ident4;
  322.                         break;
  323.         case Ident3:    *EnumParOut = Ident2; break;
  324.         case Ident4:    break;
  325.         case Ident5:    *EnumParOut = Ident3;
  326.         }
  327. }
  328.  
  329. Proc7(IntParI1, IntParI2, IntParOut)
  330. OneToFifty      IntParI1;
  331. OneToFifty      IntParI2;
  332. OneToFifty      *IntParOut;
  333. {
  334.         REG OneToFifty  IntLoc;
  335.  
  336.         IntLoc = IntParI1 + 2;
  337.         *IntParOut = IntParI2 + IntLoc;
  338. }
  339.  
  340. Proc8(Array1Par, Array2Par, IntParI1, IntParI2)
  341. Array1Dim       Array1Par;
  342. Array2Dim       Array2Par;
  343. OneToFifty      IntParI1;
  344. OneToFifty      IntParI2;
  345. {
  346.         REG OneToFifty  IntLoc;
  347.         REG OneToFifty  IntIndex;
  348.  
  349.         IntLoc = IntParI1 + 5;
  350.         Array1Par[IntLoc] = IntParI2;
  351.         Array1Par[IntLoc+1] = Array1Par[IntLoc];
  352.         Array1Par[IntLoc+30] = IntLoc;
  353.         for (IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
  354.                 Array2Par[IntLoc][IntIndex] = IntLoc;
  355.         ++Array2Par[IntLoc][IntLoc-1];
  356.         Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc];
  357.         IntGlob = 5;
  358. }
  359.  
  360. Enumeration Func1(CharPar1, CharPar2)
  361. CapitalLetter   CharPar1;
  362. CapitalLetter   CharPar2;
  363. {
  364.         REG CapitalLetter       CharLoc1;
  365.         REG CapitalLetter       CharLoc2;
  366.  
  367.         CharLoc1 = CharPar1;
  368.         CharLoc2 = CharLoc1;
  369.         if (CharLoc2 != CharPar2)
  370.                 return (Ident1);
  371.         else
  372.                 return (Ident2);
  373. }
  374.  
  375. boolean Func2(StrParI1, StrParI2)
  376. String30        StrParI1;
  377. String30        StrParI2;
  378. {
  379.         REG OneToThirty         IntLoc;
  380.         REG CapitalLetter       CharLoc;
  381.  
  382.         IntLoc = 1;
  383.         while (IntLoc <= 1)
  384.                 if (Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1)
  385.                 {
  386.                         CharLoc = 'A';
  387.                         ++IntLoc;
  388.                 }
  389.         if (CharLoc >= 'W' && CharLoc <= 'Z')
  390.                 IntLoc = 7;
  391.         if (CharLoc == 'X')
  392.                 return(TRUE);
  393.         else
  394.         {
  395.                 if (strcmp(StrParI1, StrParI2) > 0)
  396.                 {
  397.                         IntLoc += 7;
  398.                         return (TRUE);
  399.                 }
  400.                 else
  401.                         return (FALSE);
  402.         }
  403. }
  404.  
  405. boolean Func3(EnumParIn)
  406. REG Enumeration EnumParIn;
  407. {
  408.         REG Enumeration EnumLoc;
  409.  
  410.         EnumLoc = EnumParIn;
  411.         if (EnumLoc == Ident3) return (TRUE);
  412.         return (FALSE);
  413. }
  414.  
  415. #ifdef  NOSTRUCTASSIGN
  416. memcpy(d, s, l)
  417. register char   *d;
  418. register char   *s;
  419. int     l;
  420. {
  421.         while (l--) *d++ = *s++;
  422. }
  423. #endif
  424.  
  425. /*
  426.  *      Library function for compilers with no time(2) function in the
  427.  *      library.
  428.  */
  429. #ifdef  NOTIME
  430. long    time(p)
  431. long    *p;
  432. {               /* CI-C86 time function - don't use around midnight */
  433.         long    t;
  434.         struct regval {unsigned int ax,bx,cx,dx,si,di,ds,es; } regs;
  435.  
  436.         regs.ax = 0x2c00;
  437.         sysint21(®s, ®s);
  438.         t = ((regs.cx>>8)*60L + (regs.cx & 0xff))*60L + (regs.dx>>8);
  439.         if (p) *p = t;
  440.         return t;
  441. }
  442. #endif
  443.  
  444.  
  445.